﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinesys.Entities;
using Chinesys.Domain.InputValidations.Common;

namespace Chinesys.Domain.InputValidations
{
    public class UserInputValidations : InputValidationBase
    {
        private UserEntity user;

        public UserInputValidations(UserEntity user)
        {
            this.user = user;
        }

        public override void Validate()
        {
            if (string.IsNullOrEmpty(user.Address))
                Errors.Add(new Required("Address"));

            if (string.IsNullOrEmpty(user.Email))
                Errors.Add(new Required("Email"));

            if (string.IsNullOrEmpty(user.FirstName))
                Errors.Add(new Required("First Name"));

            if (string.IsNullOrEmpty(user.LastName))
                Errors.Add(new Required("Last Name"));

            if (string.IsNullOrEmpty(user.Pass))
                Errors.Add(new Required("Password"));

            if (string.IsNullOrEmpty(user.PhoneOne))
                Errors.Add(new Required("Primary Phone"));

            if (string.IsNullOrEmpty(user.UserName))
                Errors.Add(new Required("User Name"));

            if (user.Address.Length > 2000)
                Errors.Add(new Lenght("Address", 2000));

            if (user.Email.Length > 200)
                Errors.Add(new Lenght("Email", 200));

            if (user.FirstName.Length > 200)
                Errors.Add(new Lenght("First Name", 200));

            if (user.LastName.Length > 200)
                Errors.Add(new Lenght("Last Name", 200));

            if (user.Pass.Length > 11)
                Errors.Add(new Lenght("Password", 11));

            if (user.PhoneOne.Length > 200)
                Errors.Add(new Lenght("Primary Phone", 200));

            if (!string.IsNullOrEmpty(user.PhoneTwo) && user.PhoneTwo.Length > 200)
                Errors.Add(new Lenght("Phone Two", 200));

            if (!string.IsNullOrEmpty(user.PhoneThree) && user.PhoneThree.Length > 200)
                Errors.Add(new Lenght("Phone Three", 200));

            if (user.UserName.Length > 200)
                Errors.Add(new Lenght("User Name", 200));

            EmailAddress emailValidation = new EmailAddress(() => user.Email);
            if (emailValidation.IsNotValid())
            {
                Errors.Add(new GeneralValidation(emailValidation.Message));
            }

            if (user.UserName.Contains(' '))
            {
                Errors.Add(new GeneralValidation("El UserName no pude tener espacios."));
            }
        }
    }
}
